package cn.edu.njpi.controller;

import cn.edu.njpi.model.TUser;
import cn.edu.njpi.service.TUserService;
import cn.edu.njpi.utils.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 朱宗辉
 * @version V1.0
 * @Package cn.edu.njpi.controller
 * @date 2022/4/19 6:33 PM
 */
@RestController
@RequestMapping(value = "/api/user")
public class UserController {
    @Autowired
    private TUserService tUserService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public T login(@RequestBody TUser tUser) {
        T t = new T();
        Object o = tUserService.login(tUser);
        if (o == null) {
            t.add("error", "账号或密码错误");
            t.setStatus(402);
        } else {
            t.add("user", o);
            t.setStatus(200);
        }
        return t;
    }
}
